<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="styleSheet" href="../../css/bootstrap.min.css"> 
<title>出租意向详情</title>
<style type="text/css">
	#purposeDiv{
		margin-left: 60px;
		margin-top: 30px;
		width: 600px;
	}
	#tableDiv{
		margin-left: 60px;
		margin-top: 30px;
		width: 1000px;
	}
	#fenyeDiv{
		margin-left: 60px;
		margin-top: 80px;
		width: 1000px;
		text-align: center;
	}
	.col-sm-4{
		margin-top:20px;
		
	}
	.form-control{
		margin-top:-5px;
	}
	td{
		text-align: center;
	}
	
</style>
</head>
<body style="background-color: transparent;">
	<div id="purposeDiv">
		<div class="row">
            <div class="col-xs-6 col-sm-4">
                <label style="float:right;">出租车位:</label>
             </div>
             <div class="col-xs-6 col-sm-4">
                 <input class="form-control" readonly="readonly" type="text" id="rentCarPort" name="rentCarPort">
             </div>
        </div>
        <div class="row">
            <div class="col-xs-6 col-sm-4">
                <label style="float:right;">开始时间:</label>
             </div>
             <div class="col-xs-6 col-sm-4">
                 <input class="form-control" readonly="readonly" type="text" id="startTime" name="startTime">
             </div>
        </div>
        <div class="row">
            <div class="col-xs-6 col-sm-4">
                <label style="float:right;">结束时间:</label>
             </div>
             <div class="col-xs-6 col-sm-4">
                 <input class="form-control" readonly="readonly" type="text" id="endTime" name="endTime">
             </div>
        </div>
		<label><input type="hidden" id="ladyID" value="${sessionScope.myLandLady.ladyID }"></label>
	</div>
	<div id="tableDiv">
		<table id="purposeTable" class="table table-striped table table-bordered">
			<tr>
			<td>编号</td>
			<td>抢租客</td>
			<td>职业</td>
			<td>联系电话</td>
			<td>信誉度</td>
			<td>留言</td>
			<td>操作</td>
			</tr>
		</table>
	
	</div>
	<div id="fenyeDiv" class="fenyeDiv">
	<ul class="pager">
			<li><a href="javascript:void(0)" id="firstPage">首页</a></li>
			<li><a href="javascript:void(0)" id="pageUp">前一页</a></li>
			<li><label id="currentPage"></label><label>/</label><label
				id="pageCount"></label></li>
			<li><a href="javascript:void(0)" id="pageDown">下一页</a></li>
			<li><a href="javascript:void(0)" id="lastPage">末页</a></li>
	</ul>
	</div>
</body>
<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
	$(function(){
		init();
	})
	function init(){
		show(1);
	}
	function show(curPage){
		var id = getParam("id");
		$.ajax({
			url:"showAboutThisRentInfo.do",
			type:"post",
			async:true,
			data:{"id":id,"curPage":curPage},
			success:function(msg){
				var tr="";
				$("#rentCarPort").val(msg.list[0].rentInfo.personalcarport.carportAddress+msg.list[0].rentInfo.personalcarport.carNO);
				var startTime =new Date(msg.list[0].rentInfo.startTime);
				$("#startTime").val(startTime.getFullYear()+"年"+(startTime.getUTCMonth()+1)+"月"+(startTime.getUTCDate()+1)+"日"+startTime.getHours()+"时");
				var endTime =new Date(msg.list[0].rentInfo.endTime);
				$("#endTime").val(endTime.getFullYear()+"年"+(endTime.getUTCMonth()+1)+"月"+(endTime.getUTCDate()+1)+"日"+endTime.getHours()+"时");
				for (var i = 0; i < msg.list.length; i++) {
					var index = new Number(i+1);
					tr+="<tr><td>"+index+"</td><td >"+msg.list[i].renter.renterName+"</td><td>"+msg.list[i].renter.renterDescribe+"</td><td>"+msg.list[i].renter.renterTel+"</td><td>"+msg.list[i].renter.renterRP+"</td><td>"+msg.list[i].note+"</td><td><button class='ok btn btn-success' id='"+msg.list[i].rentInfo.personalcarport.carportID+"' name='"+msg.list[i].renter.renterID+"' value='"+msg.list[i].purposeID+"' lang='"+msg.list[i].rentInfo.rentInfoID+"'>成交</button></td></tr>"
				}
				if(msg.list.length==0){
					$("#currentPage").html("0");
					$("#pageCount").html("0");
				}
				else{
					$("#currentPage").html(msg.curPage);
					$("#pageCount").html(msg.countPage);
				}
					$("#purposeTable").append(tr);
					
				}
			
		})
	}
	 function getParam(url){
		 var reg
		 = new RegExp("(^|&)"+
		 url +"=([^&]*)(&|$)");
		 var r
		 = window.location.search.substr(1).match(reg);
		if (r!=null) return unescape(r[2]); return null;
		
	 
	 }
	$(".pager a").click	(function(){
	var curPage=$("#currentPage").html();
	var countPage=$("#pageCount").html();
	var pageFtn=$(this).html();
	
	if(pageFtn=="首页"){
		curPage=1;
	}
	if(pageFtn=="前一页"){
		
		curPage=parseInt(curPage)-1;
		if(curPage<1){
			curPage=1;
		}
	}
	if(pageFtn=="下一页"){
		
		curPage=parseInt(curPage)+1;
		if(curPage>countPage){
			curPage=countPage;
		}
	}
	if(pageFtn=="末页"){
		
		curPage=countPage;
	}
	$("#purposeTable tr:gt(0)").remove();
	$("#currentPage").html(curPage);
	
	show(curPage);
		
	});
	$(".ok").live("click",function(){
		var carPortId = $(this).attr("id");
		var renterId = $(this).attr("name")
		var ladyId = $("#ladyID").val();
		var purposeID = $(this).attr("value")
		var rentInfoID = $(this).attr("lang"); 
		$.ajax({
			url:"agreeToRentCarPort.do",
			type:"post",
			async:true,
			data:{"carPortID":carPortId,"renterID":renterId,"ladyID":ladyId,"purposeID":purposeID,"rentInfoID":rentInfoID},
			success:function(msg){
				window.location.href="waitRent.jsp";
			}
		})
	})
</script>
</html>